package top.martinzh.stock.manager;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Service;

import top.martinzh.stock.entity.Company;

/**
 * 上市公司管理
 * @author martin
 *
 */
@Service
public class CompanyManager {

	private List<Company> companyList = new ArrayList<Company>();

	public Optional<Company> getByCode(String code) {
		return companyList.stream().filter(c->c.getCode().equals(code)).findFirst();
	}

	public Company add(String name, double issuePrice, int amount) {
		
		String code = String.format("6%5s", companyList.size() + 1).replaceAll("\\s", "0");
		
		Company company = new Company();
		company.setName(name);
		company.setIssuePrice(issuePrice);
		company.setAmount(amount);
		company.setCode(code);
		companyList.add(company);
		
		return company;
	}
	
}
